package su.samlib.informer.model;

import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;

public class Book implements Parcelable {
	public String sectionName;
	public String book_description;
	public String genres;
	public String bookUri;
	public String title;
	public int size;
	public int size_old;
	public Date update_date = new Date();
	public boolean isNew;

	public String toString(){
		return "[" + "\n" +
				"Title: " + title + "\n" +
				"Link: " + bookUri +  "\n" +
				"Size: " + size + "\n" +
				"]";
	}
	
	public void setBookSize(int size) {
		this.size = size;
	}
	
	public int getBookSize() {
		return size;
	}
	
	public void setSection(final String sectionName) {
		this.sectionName = sectionName;
	}

	public String getSection() {
		if (sectionName == null)
			return new String();

		return sectionName;
	}

	public void setBookDescription(final String description) {
		this.book_description = description;
	}

	public String getBookDescription() {
		if (book_description == null)
			return new String();
		return book_description;
	}

	public void setBookUri(final String link) {
		this.bookUri = link;
	}
	public String getBookUri() {
		if (bookUri == null)
			return new String();
		return bookUri;
	}
	
	public void setGenres(final String genres) {
		this.genres = genres;
	}
	
	public String getGenres() {
		if (genres == null)
			return new String();
		return genres;
	}

	public void setBookTitle(final String title) {
		this.title = title;
	}

	public String getTitle() {
		if (title == null)
			return new String();
		return title;
	}

	public boolean isNew() {
		return isNew;
	}

	public void setIsNew() {
		isNew = true;
	}

	public Book() {
	}

	public Book(Parcel in) {
		sectionName = in.readString();
		book_description = in.readString();
		genres = in.readString();
		bookUri = in.readString();
		title = in.readString();
		size = in.readInt();
		size_old = in.readInt();
//		update_date = new Date(Date.parse(in.readString()));
		boolean isNewArray[] = new boolean[1];
		in.readBooleanArray(isNewArray);
		isNew = isNewArray[0];
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(sectionName);
		dest.writeString(book_description);
		dest.writeString(genres);
		dest.writeString(bookUri);
		dest.writeString(title);
		dest.writeInt(size);
		dest.writeInt(size_old);
//		dest.writeString(update_date.toString());
		boolean isNewArray[] = new boolean[1];
		isNewArray[0] = isNew;
		dest.writeBooleanArray(isNewArray);

	}

	public static final Parcelable.Creator<Book> CREATOR = new Parcelable.Creator<Book>() {

		public Book createFromParcel(Parcel in) {
			return new Book(in);
		}
		public Book[] newArray(int size) {
			return new Book[size];
		}
	};
}
